Skip to content

Add Solana TWAP documentation #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 30, 2025
Merged

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Add user-facing documentation for the new Solana TWAP feature as requested by Tejas Badadare ([email protected]).

Link to Devin run: https://app.devin.ai/sessions/8fc45da0232549e5a9f87dbc5d54495d

Co-Authored-By: Tejas Badadare <[email protected]>
Copy link

vercel bot commented Mar 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 30, 2025 8:33pm
documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 30, 2025 8:33pm

Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Comment on lines 248 to 250
<Callout type="warning" emoji="⚠️">
The TWAP window is currently limited to a maximum of 10 minutes (600 seconds).
</Callout>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't make this a callout, just add the sentence to the previous block

use pyth_solana_receiver_sdk::price_update::{TwapUpdate};

#[derive(Accounts)]
#[instruction(amount_in_usd : u64, twap_window_seconds: u64)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amount_in_usd is unused in this example, remove it.


### Using TWAP in Solana Programs

To use TWAP in your Solana program, import the `TwapUpdate` struct from the Pyth Solana receiver SDK:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that this process is the same as pulling a regular price update from hermes and posting it on chain

…nused parameter, mention similarity to regular price updates

Co-Authored-By: Tejas Badadare <[email protected]>
Comment on lines 366 to 373
The [Solana TWAP example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/solana/send_usd) demonstrates how to fetch TWAP data from Hermes, post it to Solana, and consume it from a smart contract. The example includes:

- A React frontend for interacting with the contract
- A Solana program that consumes TWAP updates
- Complete transaction building for posting and consuming TWAP data

The example allows users to send a USD-denominated amount of SOL using either spot prices or TWAP prices, demonstrating how TWAP can be used to reduce the impact of price volatility.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might clarify the wording here since I believe this is an existing demo app to which you've added TWAP functionality.

Copy link

@merolish merolish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@tejasbadadare tejasbadadare merged commit 0980475 into main Mar 30, 2025
3 of 5 checks passed
@tejasbadadare tejasbadadare deleted the devin/1743107646-solana-twap-docs branch March 30, 2025 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants